<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="username">
    <input type="button" value="验证" id="btn">
    <script>
        var username = document.querySelector('#username');
        var btn = document.querySelector('#btn')
        btn.onclick = function () {
            var reg = /^[a-z\u4e00-\u9fa5]{2,14}$/i;
            var res = reg.test(username.value);
            if (res) {
                var len = username.value.replace(/[\u4e00-\u9fa5]/g, 'zz');
                if (len.length > 14) {
                    alert('用户名长度只能为7个汉字或者14个英文')
                } else {
                    alert('验证成功')
                }
            } else {
                alert('验证失败')
            }
        }
    </script>
</body>

</html>